change the file extension when the file format is changed in the Print
authorSven Neumann <sven@gimp.org>
Thu, 9 Aug 2007 15:05:23 +0000 (15:05 +0000)
committerSven Neumann <neo@src.gnome.org>
Thu, 9 Aug 2007 15:05:23 +0000 (15:05 +0000)
2007-08-09  Sven Neumann  <sven@gimp.org>

* modules/printbackends/file/gtkprintbackendfile.c: change the
file extension when the file format is changed in the Print dialog
(#356630).

svn path=/trunk/; revision=18600

ChangeLog
modules/printbackends/file/gtkprintbackendfile.c

index 3aaeb5f61e7b97f9f9583b82ed027e11a5947ba6..cb552cd99d4b3ff1fd1cbd8e6ba8c7b951773e65 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-08-09  Sven Neumann  <sven@gimp.org>
+
+       * modules/printbackends/file/gtkprintbackendfile.c: change the
+       file extension when the file format is changed in the Print dialog
+       (#356630).
+
 2007-08-09  Stefan Kost  <ensonic@users.sf.net>
 
        * docs/reference/gtk/tmpl/gtkruler.sgml:
index 7dae376cb3953a273162caf244c02ddc28721549..7ab8d4d9ce7c7066aab6ca831427d5c73da6de8c 100644 (file)
@@ -194,7 +194,8 @@ format_from_settings (GtkPrintSettings *settings)
   if (settings == NULL)
     return N_FORMATS;
 
-  value = gtk_print_settings_get (settings, GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
+  value = gtk_print_settings_get (settings,
+                                  GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
   if (value == NULL)
     return N_FORMATS;
 
@@ -476,6 +477,58 @@ gtk_print_backend_file_init (GtkPrintBackendFile *backend)
   gtk_print_backend_set_list_done (GTK_PRINT_BACKEND (backend));
 }
 
+static void
+file_printer_output_file_format_changed (GtkPrinterOption    *format_option,
+                                         GtkPrinterOptionSet *set)
+{
+  GtkPrinterOption *uri_option;
+  gchar            *base = NULL;
+
+  if (! format_option->value)
+    return;
+
+  uri_option = gtk_printer_option_set_lookup (set,
+                                              "gtk-main-page-custom-input");
+
+  if (uri_option && uri_option->value)
+    {
+      const gchar *uri = uri_option->value;
+      const gchar *dot = strrchr (uri, '.');
+
+      if (dot)
+        {
+          gint i;
+
+          /*  check if the file extension matches one of the known ones  */
+          for (i = 0; i < N_FORMATS; i++)
+            if (strcmp (dot + 1, formats[i]) == 0)
+              break;
+
+          if (i < N_FORMATS && strcmp (formats[i], format_option->value))
+            {
+              /*  the file extension is known but doesn't match the
+               *  selected one, strip it away
+               */
+              base = g_strndup (uri, dot - uri);
+            }
+        }
+      else
+        {
+          /*  there's no file extension  */
+          base = g_strdup (uri);
+        }
+    }
+
+  if (base)
+    {
+      gchar *tmp = g_strdup_printf ("%s.%s", base, format_option->value);
+
+      gtk_printer_option_set (uri_option, tmp);
+      g_free (tmp);
+      g_free (base);
+    }
+}
+
 static GtkPrinterOptionSet *
 file_printer_get_options (GtkPrinter           *printer,
                          GtkPrintSettings     *settings,
@@ -562,7 +615,11 @@ file_printer_get_options (GtkPrinter           *printer,
                                             display_format_names);
       gtk_printer_option_set (option, supported_formats[current_format]);
       gtk_printer_option_set_add (set, option);
-      
+
+      g_signal_connect (option, "changed",
+                        G_CALLBACK (file_printer_output_file_format_changed),
+                        set);
+
       g_object_unref (option);
     }